feat: add autocomplete for conditional arguments#194
Merged
Conversation
Add Select2-based autocomplete for conditional arguments (categories, tags, pages, posts) to make it easier for users to select values when configuring ad code conditions. Key implementation details: - Uses WordPress's bundled SelectWoo/Select2 library - AJAX search with 3-character minimum and 100 result limit - Supports both taxonomy terms and post type searches - Allows custom values via Select2's tags option - Extensible via `acm_autocomplete_conditionals` and `acm_autocomplete_results` filters Fixes #42 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Select2 with AJAX data requires hidden inputs, not text inputs. Also fix test pollution by dequeuing scripts between tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Select2/selectWoo is not bundled with WordPress core - it comes from WooCommerce. When neither selectWoo nor select2 is registered, we now load Select2 v4.0.13 from jsDelivr CDN. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Select2 with AJAX requires a <select> element, not an input. Dynamically create a select element when initializing autocomplete and restore the original input when switching conditionals. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Conditionals like is_home, is_front_page, is_404, etc. don't accept arguments, so showing an input field is confusing. Now the arguments field is hidden when these conditionals are selected. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Change "Add more" to "Add another condition" - Remove boxed styling from Configuration section - Fix Select2 field heights to match native inputs - Fix Edit labels to use proper labels from provider config - Link labels to their corresponding form fields - Hide "Add another condition" button until first condition selected - Show Logical Operator only when 2+ conditions are set - Move Logical Operator field near Conditionals in Edit view 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove inline edit autocomplete initialization (will be addressed with dedicated edit page in future PR) - Scope all autocomplete functionality to #add-adcode form only - Add isSelect2Available() check to gracefully handle CDN failures - Prevent JS errors when Select2 fails to load 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
acm_autocomplete_conditionalsandacm_autocomplete_resultsfiltersNote: Autocomplete is currently only enabled for the Add form. The inline Edit form retains text inputs - a dedicated edit page is planned as a follow-up improvement (see #198).
Test plan
is_categoryoris_tagis_homeoris_front_pageand verify arguments field is hiddencomposer test:integration- all 28 tests should passFixes #42
🤖 Generated with Claude Code